package com.aspose.cells;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

public class ConditionalFormattingCollection extends CollectionBase {
   Worksheet b;

   ConditionalFormattingCollection(Worksheet sheet) {
      this.b = sheet;
   }

   public void removeArea(int startRow, int startColumn, int totalRows, int totalColumns) {
      for(int var5 = 0; var5 < this.getCount(); ++var5) {
         FormatConditionCollection var6 = this.get(var5);
         if (var6.removeArea(startRow, startColumn, totalRows, totalColumns)) {
            this.a.remove(var5--);
         }
      }

   }

   public void copy(ConditionalFormattingCollection cfs) {
      this.b.c = cfs.b.c;

      for(int var2 = 0; var2 < cfs.getCount(); ++var2) {
         FormatConditionCollection var3 = new FormatConditionCollection(this);
         var3.a(cfs.get(var2), (CopyOptions)null);
         com.aspose.cells.b.a.a.ze.a(this.a, (Object)var3);
      }

   }

   void a(ConditionalFormattingCollection var1, CopyOptions var2) {
      this.b.c = var1.b.c;

      for(int var3 = 0; var3 < var1.getCount(); ++var3) {
         FormatConditionCollection var4 = new FormatConditionCollection(this);
         var4.a(var1.get(var3), var2);
         com.aspose.cells.b.a.a.ze.a(this.a, (Object)var4);
      }

   }

   void a(ConditionalFormattingCollection var1, int var2, int var3, int var4, CopyOptions var5, boolean var6) {
      CellArea var7 = CellArea.createCellArea(0, var2, 16383, var2 + var4 - 1);
      CellArea var8 = CellArea.createCellArea(0, var3, 16383, var3 + var4 - 1);
      this.a(var1, var7, var8, var5, var6);
   }

   void a(ConditionalFormattingCollection var1, CellArea var2, CellArea var3, CopyOptions var4, boolean var5) {
      if (!var5) {
         boolean var10000 = var1 == this;

         for(int var7 = 0; var7 < var1.getCount(); ++var7) {
            FormatConditionCollection var8 = var1.get(var7);
            int var9 = var8.b.size();

            for(int var10 = 0; var10 < var9; ++var10) {
               CellArea var11 = (CellArea)var8.b.get(var10);
               Object var12 = zayd.e(var11, var2);
               if (var12 != null) {
                  var11 = (CellArea)var12;
                  CellArea var13 = new CellArea();
                  var13.StartRow = var11.StartRow - var2.StartRow + var3.StartRow;
                  var13.StartColumn = var11.StartColumn - var2.StartColumn + var3.StartColumn;
                  var13.EndRow = var11.EndRow - var11.StartRow + var13.StartRow;
                  var13.EndColumn = var11.EndColumn - var11.StartColumn + var13.StartColumn;
                  if (var1 == this) {
                     zayd.a(var8.b, var13);
                  } else {
                     FormatConditionCollection var14 = new FormatConditionCollection(this);
                     var14.a(var8, var13, var4);
                     com.aspose.cells.b.a.a.ze.a(this.a, (Object)var14);
                  }
               }
            }
         }

      }
   }

   public FormatConditionCollection get(int index) {
      return (FormatConditionCollection)this.a.get(index);
   }

   public int add() {
      com.aspose.cells.b.a.a.ze.a(this.a, (Object)(new FormatConditionCollection(this)));
      return this.getCount() - 1;
   }

   int a(FormatConditionCollection var1) {
      com.aspose.cells.b.a.a.ze.a(this.a, (Object)var1);
      return this.getCount() - 1;
   }

   void a(int var1, int var2, int var3, int var4) {
      for(int var5 = 0; var5 < this.getCount(); ++var5) {
         FormatConditionCollection var6 = this.get(var5);
         Iterator var7 = var6.b.iterator();

         while(var7.hasNext()) {
            CellArea var8 = (CellArea)var7.next();
            if (var1 >= var8.StartRow && var1 <= var8.EndRow && var2 >= var8.StartColumn && var2 <= var8.EndColumn) {
               for(int var9 = var6.getRangeCount() - 1; var9 >= 0; --var9) {
                  CellArea var10 = (CellArea)var6.b.get(var9);
                  if (var3 >= var10.StartRow && var3 <= var10.EndRow) {
                     if (var4 >= var10.StartColumn && var4 <= var10.EndColumn) {
                        return;
                     }

                     if (var10.StartRow == var10.EndRow) {
                        if (var4 == var10.StartColumn - 1) {
                           --var10.StartColumn;
                           var6.b.set(var9, var10);
                           return;
                        }

                        if (var4 == var10.EndColumn + 1) {
                           ++var10.EndColumn;
                           var6.b.set(var9, var10);
                           return;
                        }
                     }
                  }

                  if (var10.StartColumn == var10.EndColumn) {
                     if (var3 == var10.StartRow - 1) {
                        --var10.StartRow;
                        var6.b.set(var9, var10);
                        return;
                     }

                     if (var3 == var10.EndRow + 1) {
                        ++var10.EndRow;
                        var6.b.set(var9, var10);
                        return;
                     }
                  }
               }

               CellArea var11 = new CellArea();
               var11.StartRow = var3;
               var11.StartColumn = var4;
               var11.EndRow = var3;
               var11.EndColumn = var4;
               var6.b.add(0, var11);
               return;
            }
         }
      }

   }

   void a(ConditionalFormattingCollection var1, int var2, int var3, int var4) {
      int var5;
      if (var1 != this) {
         for(var5 = 0; var5 < var1.getCount(); ++var5) {
            FormatConditionCollection var6 = var1.get(var5);
            this.a(var6, var2, var3, var4);
         }
      } else {
         var5 = this.getCount();

         for(int var8 = 0; var8 < var5; ++var8) {
            FormatConditionCollection var7 = this.get(var8);
            this.a(var7.b, var2, var3, var4);
         }
      }

   }

   private void a(FormatConditionCollection var1, int var2, int var3, int var4) {
      ArrayList var5 = var1.b;
      ArrayList var6 = new ArrayList();

      for(int var7 = var5.size() - 1; var7 >= 0; --var7) {
         CellArea var8 = (CellArea)var5.get(var7);
         Object var9 = zayd.b(var8, var2, var4);
         if (var9 != null) {
            CellArea var10 = (CellArea)var9;
            int var11 = var8.StartRow - var2;
            if (var11 < 0) {
               var11 = 0;
            }

            int var12 = var3 + var11;
            int var13 = var10.EndRow - var10.StartRow + 1;
            CellArea var14 = new CellArea();
            var14.StartRow = var12;
            var14.EndRow = var12 + var13 - 1;
            var14.StartColumn = var8.StartColumn;
            var14.EndColumn = var8.EndColumn;
            com.aspose.cells.b.a.a.ze.a(var6, (Object)var14);
         }
      }

      if (var6.size() != 0) {
         FormatConditionCollection var15 = new FormatConditionCollection(this);
         var15.a(var1, var6);
         com.aspose.cells.b.a.a.ze.a(this.a, (Object)var15);
      }

   }

   private void a(ArrayList var1, int var2, int var3, int var4) {
      int var5;
      CellArea var6;
      for(var5 = var1.size() - 1; var5 >= 0; --var5) {
         var6 = (CellArea)var1.get(var5);
         ArrayList var7 = zayd.a(var6, var3, var4);
         var1.remove(var5);
         var1.addAll(var5, var7);
      }

      for(var5 = var1.size() - 1; var5 >= 0; --var5) {
         var6 = (CellArea)var1.get(var5);
         Object var16 = zayd.b(var6, var2, var4);
         if (var16 != null) {
            CellArea var8 = (CellArea)var16;
            int var9 = var6.StartRow - var2;
            int var10 = var3 + var9;
            int var11 = var8.EndRow;
            int var12 = var11 - var8.StartRow + 1;
            CellArea var13 = new CellArea();
            var13.StartRow = var10;
            var13.EndRow = var10 + var12 - 1;
            var13.StartColumn = var6.StartColumn;
            var13.EndColumn = var6.EndColumn;
            boolean var14 = false;
            boolean[] var15 = new boolean[]{var14};
            var6 = zayd.a(var6, var13, var15);
            var14 = var15[0];
            if (var14) {
               var1.set(var5, var6);
            } else {
               com.aspose.cells.b.a.a.ze.a(var1, (Object)var13);
            }
         }
      }

   }

   void a(FormatConditionCollection var1, ArrayList var2) {
      for(int var3 = var2.size() - 1; var3 > 0; --var3) {
         int var4 = this.add();
         FormatConditionCollection var5 = this.get(var4);
         var5.c = var1.c;
         com.aspose.cells.b.a.a.ze.a(var5.b, var2.get(var3));

         for(int var6 = 0; var6 < var1.getCount(); ++var6) {
            FormatCondition var7 = new FormatCondition(var5);
            var7.a((FormatCondition)var1.get(var6), (CopyOptions)null);
            var7.setPriority(this.b.c++);
            var5.a(var7);
         }
      }

      var1.b.clear();
      com.aspose.cells.b.a.a.ze.a(var1.b, var2.get(0));
   }

   void b(FormatConditionCollection var1) {
      ArrayList var2 = var1.b;

      int var3;
      for(var3 = var2.size() - 1; var3 > 0; --var3) {
         int var4 = this.add();
         FormatConditionCollection var5 = this.get(var4);
         var5.c = var1.c;
         CellArea var6 = (CellArea)var2.get(var3);
         CellArea var7 = new CellArea();
         var7.StartRow = var6.StartRow;
         var7.StartColumn = var6.StartColumn;
         var7.EndColumn = var6.EndColumn;
         var7.EndRow = var6.EndRow;
         com.aspose.cells.b.a.a.ze.a(var5.b, (Object)var7);

         for(int var8 = 0; var8 < var1.getCount(); ++var8) {
            FormatCondition var9 = new FormatCondition(var5);
            var9.a((FormatCondition)var1.get(var8), (CopyOptions)null);
            var9.setPriority(this.b.c++);
            var5.a(var9);
         }

         var2.remove(var3);
      }

      for(var3 = 0; var3 < var1.getCount(); ++var3) {
         var1.get(var3).d = null;
         var1.get(var3).e = null;
      }

   }

   void a(CellArea var1, int var2, int var3, Worksheet var4, boolean var5) {
      switch(var3) {
      case 0:
         this.b(var1, var2, var4, var5);
         break;
      case 3:
         this.a(var1, var2, var4, var5);
      }

   }

   private void a(FormatConditionCollection var1, CellArea var2, int var3, int var4, Worksheet var5, boolean var6, int var7, int var8, int var9, int var10) {
      for(int var11 = 0; var11 < var1.getCount(); ++var11) {
         FormatCondition var12 = var1.get(var11);
         byte[] var13;
         if (var12.a() != null) {
            var13 = var12.a();
            zyo.a(var2, var3, var4, var5, var6, var13, -1, var13.length, var7, var8, var9, var10);
            var12.a(var13);
         }

         if ((var12.getOperator() == 0 || var12.getOperator() == 7) && var12.c() != null) {
            var13 = var12.c();
            zyo.a(var2, var3, var4, var5, var6, var13, -1, var13.length, var7, var8, var9, var10);
            var12.b(var13);
         }
      }

   }

   private void a(CellArea var1, int var2, Worksheet var3, boolean var4) {
      for(int var5 = 0; var5 < this.getCount(); ++var5) {
         FormatConditionCollection var6 = this.get(var5);
         if (var6.b != null && var6.b.size() != 0) {
            int var7 = var6.b.size();
            var6.f();
            boolean var8 = var6.d();
            ArrayList var9 = new ArrayList();
            ArrayList var10 = new ArrayList();
            zayd.d(var6.b, this.b.c().n().j(), var1, var2, var9, var10);
            int[] var11 = var6.e();
            int var12 = var11[0];
            int var13 = var11[1];
            if (var8) {
               var6.b.clear();
               if (var9.size() != 0) {
                  com.aspose.cells.b.a.a.ze.a(var6.b, (Collection)var9);
                  this.a(var6, var1, var2, 3, var3, var4, var12, var13, var12, var13);
                  if (var10.size() != 0) {
                     FormatConditionCollection var14 = new FormatConditionCollection(this);
                     var14.a(var6);
                     this.a.add(var5, var14);
                     com.aspose.cells.b.a.a.ze.a(var14.b, (Collection)var10);
                     var11 = var14.e();
                     var12 = var11[0];
                     var13 = var11[1];
                     this.a(var14, var1, var2, 3, var3, var4, var12, var13 - var2, var12, var13);
                     ++var5;
                  }
               } else if (var10.size() != 0) {
                  com.aspose.cells.b.a.a.ze.a(var6.b, (Collection)var10);
                  var11 = var6.e();
                  var12 = var11[0];
                  var13 = var11[1];
                  this.a(var6, var1, var2, 3, var3, var4, var12, var13 - var2, var12, var13);
               }
            } else {
               var6.b.clear();
               com.aspose.cells.b.a.a.ze.a(var6.b, (Collection)var9);
               com.aspose.cells.b.a.a.ze.a(var6.b, (Collection)var10);
               this.a(var6, var1, var2, 3, var3, var4, var12, var13, var12, var13);
            }
         }
      }

   }

   private void b(CellArea var1, int var2, Worksheet var3, boolean var4) {
      for(int var5 = 0; var5 < this.getCount(); ++var5) {
         FormatConditionCollection var6 = this.get(var5);
         if (var6.b != null && var6.b.size() != 0) {
            int var7 = var6.b.size();
            boolean var8 = false;
            var6.f();
            if (!var6.c() && var6.d()) {
               if (var7 > 1) {
                  this.b(var6);
               }

               CellArea var19 = (CellArea)var6.b.get(0);
               boolean[] var20 = new boolean[]{var8};
               ArrayList var21 = zayd.b(var1, var19, var20);
               var8 = var20[0];
               if (var8 && var21 != null && var21.size() > 1) {
                  this.a(var6, var21);
               }

               var19 = (CellArea)var6.b.get(0);
               int var22 = var19.StartRow;
               int var13 = var19.StartColumn;
               int var14 = var22;
               int var15 = var13;
               var20[0] = var8;
               var21 = zayd.a(var3.c().n().j(), var1, var2, var19, var20);
               var8 = var20[0];
               if (var8) {
                  var6.b = var21;
                  int[] var16 = var6.e();
                  var14 = var16[0];
                  var15 = var16[1];
               }

               for(int var23 = 0; var23 < var6.getCount(); ++var23) {
                  FormatCondition var17 = var6.get(var23);
                  byte[] var18;
                  if (var17.a() != null) {
                     var18 = var17.a();
                     zyo.a(var1, var2, 0, var3, var4, var18, -1, var18.length, var22, var13, var14, var15);
                     var17.a(var18);
                  }

                  if ((var17.getOperator() == 0 || var17.getOperator() == 7) && var17.c() != null) {
                     var18 = var17.c();
                     zyo.a(var1, var2, 0, var3, var4, var18, -1, var18.length, var22, var13, var14, var15);
                     var17.b(var18);
                  }
               }
            } else {
               for(int var9 = 0; var9 < var7; ++var9) {
                  CellArea var10 = (CellArea)var6.b.get(var9);
                  boolean[] var11 = new boolean[]{var8};
                  ArrayList var12 = zayd.a(var3.c().n().j(), var1, var2, var10, var11);
                  var8 = var11[0];
                  if (var8) {
                     if (var12.size() == 1) {
                        var6.b.set(var9, var12.get(0));
                     } else {
                        var6.b.remove(var9--);
                        --var7;
                        com.aspose.cells.b.a.a.ze.a(var6.b, (Collection)var12);
                     }
                  }
               }
            }
         }
      }

   }

   void a(int var1, int var2) {
      for(int var3 = 0; var3 < this.getCount(); ++var3) {
         FormatConditionCollection var4 = this.get(var3);
         if (var4.b != null && var4.b.size() != 0) {
            var4.f();
            if (var4.b.size() > 1 && var4.d()) {
               this.b(var4);
            }

            CellArea var5 = (CellArea)var4.b.get(0);
            int var6 = var5.StartRow;

            int var7;
            for(var7 = var4.getRangeCount() - 1; var7 >= 0; --var7) {
               CellArea var8 = (CellArea)var4.b.get(var7);
               boolean var9 = false;
               if (var2 > 0 && var1 == var8.EndRow + 1) {
                  var8.EndRow = var1 + var2 - 1;
               } else {
                  boolean[] var10 = new boolean[]{var9};
                  var8 = zayd.a(var8, var1, var2, var10);
                  var9 = var10[0];
               }

               if (var9) {
                  var4.b.remove(var7);
               } else {
                  var4.b.set(var7, var8);
               }
            }

            if (var4.getRangeCount() == 0) {
               this.removeAt(var3);
               --var3;
            } else {
               int[] var14 = var4.e();
               var7 = var14[0];
               int var13 = var14[1];
               Iterator var15 = var4.a().iterator();

               while(var15.hasNext()) {
                  FormatCondition var11 = (FormatCondition)var15.next();
                  byte[] var12 = var11.a();
                  if (var12 != null) {
                     zyo.a(this.b, true, var1, var2, var6, var7, -1, var12.length - 1, var12);
                     var11.a(var12);
                     if (var11.c() != null) {
                        var12 = var11.c();
                        zyo.a(this.b, true, var1, var2, var6, var7, -1, var12.length - 1, var12);
                        var11.b(var12);
                     }
                  }
               }
            }
         }
      }

   }

   void b(int var1, int var2) {
      for(int var3 = 0; var3 < this.getCount(); ++var3) {
         FormatConditionCollection var4 = this.get(var3);
         if (var4.b != null && var4.b.size() != 0) {
            var4.f();
            if (var4.b.size() > 1 && var4.d()) {
               this.b(var4);
            }

            CellArea var5 = (CellArea)var4.b.get(0);
            int var6 = var5.StartColumn;

            int var7;
            for(var7 = var4.getRangeCount() - 1; var7 >= 0; --var7) {
               CellArea var8 = (CellArea)var4.b.get(var7);
               boolean var9 = false;
               if (var2 > 0 && var1 == var8.EndColumn + 1) {
                  var8.EndColumn = var1 + var2 - 1;
               } else {
                  boolean[] var10 = new boolean[]{var9};
                  var8 = zayd.b(var8, var1, var2, var10);
                  var9 = var10[0];
               }

               if (var9) {
                  var4.b.remove(var7);
               } else {
                  var4.b.set(var7, var8);
               }
            }

            if (var4.getRangeCount() == 0) {
               this.removeAt(var3);
               --var3;
            } else {
               int[] var14 = var4.e();
               var7 = var14[0];
               int var13 = var14[1];
               Iterator var15 = var4.a().iterator();

               while(var15.hasNext()) {
                  FormatCondition var11 = (FormatCondition)var15.next();
                  byte[] var12 = var11.a();
                  if (var12 != null) {
                     zyo.c(this.b, true, var1, var2, var6, var13, -1, var12.length - 1, var12);
                     var11.a(var12);
                  }

                  if (var11.c() != null) {
                     var12 = var11.c();
                     zyo.c(this.b, true, var1, var2, var6, var13, -1, var12.length - 1, var12);
                     var11.b(var12);
                  }
               }
            }
         }
      }

   }

   boolean a() {
      for(int var1 = 0; var1 < this.getCount(); ++var1) {
         FormatConditionCollection var2 = this.get(var1);
         int var3 = var2.b(false);
         if (var3 != 0 && var3 != var2.getCount()) {
            var2.b();
         }

         if (var2.getRangeCount() == 0 && !var2.d) {
            this.removeAt(var1--);
         } else {
            for(int var4 = 0; var4 < var2.getCount(); ++var4) {
               FormatCondition var5 = var2.get(var4);
               if (var5 == null) {
                  var2.removeCondition(var4--);
               } else {
                  switch(var5.getType()) {
                  case 0:
                  case 1:
                     var5.f();
                     if (var5.a() == null) {
                        var2.removeCondition(var4--);
                     } else if (var5.c == 0 && (var5.b == 0 || var5.b == 7) && var5.c() == null) {
                        var2.removeCondition(var4--);
                     }
                  case 2:
                  case 3:
                  case 4:
                     break;
                  case 5:
                     if (var2.b.size() > 1) {
                        var5.setFormula1((String)null);
                     } else {
                        var5.setFormula1(var5.g());
                     }
                     break;
                  default:
                     var5.setFormula1(var5.g());
                  }
               }
            }

            if (var2.getCount() == 0) {
               this.removeAt(var1--);
            }
         }
      }

      return true;
   }

   boolean b() {
      if (this.getCount() == 0) {
         return false;
      } else {
         Iterator var1 = this.iterator();

         FormatConditionCollection var2;
         do {
            if (!var1.hasNext()) {
               return false;
            }

            var2 = (FormatConditionCollection)var1.next();
         } while(var2.b(true) == 0);

         return true;
      }
   }
}
